﻿using Microsoft.Office.Interop.Excel;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using PanhuaWin.工厂;
using PanhuaWin.系统管理;
using PanhuaWin.通用;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using DataTable = System.Data.DataTable;

namespace PanhuaWin.车间.彩涂
{
    public partial class Form彩涂报工维护 : UIPage

    {

         
        string 工厂guid1;
        string 部门编号1;
        string FormGuid;
        int 开始行;
        int 结束行;
        string 部门guid;
        string tempguid;
        string 彩涂原卷guid;
        string FormWorkType = "彩涂";
        decimal 卷的总重量;
        public Form彩涂报工维护()
        {
            InitializeComponent();
        }

        private void uiButton选择卷_Click(object sender, EventArgs e)
        {

        }

        private void uiLabel2_Click(object sender, EventArgs e)
        {

        }

        private void Form彩涂报工维护_Resize(object sender, EventArgs e)
        {
            

        }

        private void Form彩涂报工维护_Load(object sender, EventArgs e)
        {
            this.uiTextBox工厂名称.Text = pub.全局工厂名称;
            tempguid = Guid.NewGuid().ToString();
            this.uiDatePicker报工日期.Value = DateTime.Now;
            pub.ListMaterial(pub.全局工厂编号, FormWorkType, this.uiComboBox新材质);
            pub.ListWorkLine(pub.全局工厂编号, FormWorkType, this.uiComboBox产线);
            pub.ListWorkType(pub.全局工厂编号, FormWorkType, this.uiComboBox去向);
            pub.ListRank(pub.全局工厂编号, this.uiComboBox质量等级);
            pub.ListDayShift(pub.全局工厂编号, this.uiComboBoxDayShift);
            pub.List品名(this.uiComboBox品名, FormWorkType,this.uiComboBox质量等级.SelectedText);
            pub.ListQualityStandard(FormWorkType, this.uiComboBox执行标准);
            pub.ListWareHouse(this.uiComboBox仓库, pub.全局工厂guid);
            pub.ListColor(this.uiComboBox颜色);
            清理自己mac的Temp_彩涂报工原卷占用();
            string 当前班组 = pub.Get员工所属班组(pub.sys_user.UserTrueName);
            if (当前班组 == "")
            {
                pub.ListWorkTeam(pub.全局工厂编号, this.uiComboBox产线.SelectedValue.ToString(), this.uiComboBoxWorkTeam);
            }
            else
            {
                this.uiComboBoxWorkTeam.Items.Add(当前班组);
                this.uiComboBoxWorkTeam.SelectedIndex = 0;
            }
            uiComboBox产线.SelectedIndex = 0;
            uiComboBox仓库.SelectedValue = "FC1";

            uiComboBox包装.Items.Add("精包");
            uiComboBox包装.Items.Add("简包");
            uiComboBox包装.Items.Add("普包");
            uiComboBox包装.Items.Add("裸包");
            uiComboBox包装.Items.Add("无");
            uiComboBox包装.SelectedIndex = 2;
        }

        private void 清理自己mac的Temp_彩涂报工原卷占用()
        {
            string sql;
            sql = "delete Temp_彩涂报工原卷占用 where mac='" + pub.getMac() + "' ";
            pub.ExecuteSql(pub.ConnectionString, sql, "清理自己mac的Temp_彩涂报工原卷占用,Temp_彩涂报工原卷占用");
        }

        private void uiLabel31_Click(object sender, EventArgs e)
        {

        }

        private void uiLabel33_Click(object sender, EventArgs e)
        {

        }

        private void uiButton选择已发未完工_Click(object sender, EventArgs e)
        {
            Form已镀锌未彩涂 form已镀锌未彩涂 = new Form已镀锌未彩涂();
            form已镀锌未彩涂.工厂编号 = pub.全局工厂编号;
            删除自己的tempguid的数据(tempguid);  //Temp_彩涂报工原卷占用
            if (form已镀锌未彩涂.ShowDialog(this) == DialogResult.OK)
            {
                this.uiTextBox原料卷号.Text = form已镀锌未彩涂.卷信息.OutputVolumeNew;
                彩涂原卷guid = pub.Get彩涂报工guid(this.uiTextBox原料卷号.Text);
                if (彩涂原卷guid == "")
                {
                    MessageBox.Show("投入卷号选择有问题，请联系一下系统管理员处理: " + this.uiTextBox原料卷号.Text, "提示", MessageBoxButtons.OK);
                    return;
                }
                this.uiTextBox产出卷号.Text = pub.去掉前缀(this.uiTextBox原料卷号.Text);//不含前缀，不含后面的串号
                                                                            //this.uiTextBox存货编号1.Text = form已酸洗未完工.卷信息.InventoryCode;
                                                                            //this.uiTextBox存货名称1.Text = form已酸洗未完工.卷信息.InventoryName;


                uiTextBox规格型号1.Text = form已镀锌未彩涂.卷信息.OutputSize;
                string 厚度 = "";
                string 宽度 = "";
                string 虚拟值 = "";
                pub.FromSize(uiTextBox规格型号1.Text, out 厚度, out 宽度, out 虚拟值);
                this.uiTextBox厚度1.Text = 厚度;
                this.uiTextBox宽度1.Text = 宽度;
                this.uiTextBox米数.Text = form已镀锌未彩涂.卷信息.OutputMeter.ToString();
                this.uiTextBox新厚度.Text = 厚度;
                this.uiTextBox新宽度.Text = 宽度;
                this.uiTextBox产地1.Text = form已镀锌未彩涂.卷信息.OutputAddress;
                this.uiTextBox卷重量1.Text = form已镀锌未彩涂.卷信息.OutputWeight.ToString();

                this.uiTextBox新重量.Text = this.uiTextBox卷重量1.Text;
                this.uiTextBox新米数.Text = this.uiTextBox米数.Text;
                this.uiTextBox材质1.Text = form已镀锌未彩涂.卷信息.OutputMaterial;
                this.uiComboBox新材质.Text = this.uiTextBox材质1.Text;
                this.uiTextBox计量单位1.Text = "Kg";


                // this.uiComboBox去向.SelectedValue = form已酸洗未完工.卷信息.OutputNext;
                ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
               
                塞入自己的tempguid的数据(tempguid, form已镀锌未彩涂.卷信息.VolumeCodeNew);
            }
            else
            {
                彩涂原卷guid = "";
                删除自己的tempguid的数据(tempguid);  //Temp_彩涂报工原卷占用
            }



        }

        private void 塞入自己的tempguid的数据(string tempguid, string volumeCodeNew)
        {
            string sql;
            sql = "insert into Temp_彩涂报工原卷占用(guid, OriginalVolumeNew, MAC, 时间 ) values('" + tempguid + "','" + volumeCodeNew + "','" + pub.getMac() + "' ,getdate()) ";
            pub.ExecuteSql(pub.ConnectionString, sql, "删除自己的tempguid的数据,Temp_彩涂报工原卷占用");
        }

        private void 删除自己的tempguid的数据(string tempguid)
        {
            string sql;
            //sql = "delete Temp_彩涂报工原卷占用 where guid='" + tempguid + "' ";
            sql = "delete Temp_彩涂报工原卷占用 where mac='" + pub.getMac() + "' ";
            pub.ExecuteSql(pub.ConnectionString, sql, "删除自己的tempguid的数据,Temp_彩涂报工原卷占用");
        }

        private void uiComboBoxWorkShop_SelectedIndexChanged(object sender, EventArgs e)
        {
            //CleallAll();
            
            pub.ListDayShift(pub.全局工厂编号, this.uiComboBoxDayShift);
            pub.ListWorkLine(pub.全局工厂编号, "彩涂", this.uiComboBox产线);
            pub.ListRank(pub.全局工厂编号, this.uiComboBox质量等级);
            pub.ListDayShift(pub.全局工厂编号, this.uiComboBoxDayShift);
        }

        private void CleallAll()
        {
            this.uiDataGridView产出.DataSource = null;
            this.uiDataGridView产出.Refresh();
         
            this.uiTextBox产地1.Text = "";
            this.uiCheckBox拆成多卷.Checked = false;
            this.numericUpDown1.Value = 1;
            uiTextBox原料卷号.Text = "";
            this.uiTextBox产出卷号.Text = "";
            彩涂原卷guid = "";
            删除自己的tempguid的数据(tempguid);

            this.uiTextBox存货编号1.Text = "";
            this.uiTextBox存货名称1.Text = "";
            this.uiTextBox轧制规格.Text = "";
            this.uiTextBox成品规格.Text = "";
            this.uiTextBox备注1.Text = "";
            uiTextBox规格型号1.Text = "";
            string 厚度 = "";
            string 宽度 = "";
            string 虚拟值 = "";

            this.uiTextBox厚度1.Text = 厚度;
            this.uiTextBox宽度1.Text = 宽度;
            this.uiTextBox虚拟值1.Text = 虚拟值;
            this.uiTextBox新厚度.Text = 厚度;
            this.uiTextBox新宽度.Text = 宽度;
            this.uiTextBox产地1.Text = "";
            this.uiTextBox卷重量1.Text = "";
            this.uiTextBox材质1.Text = "";
            //this.uiComboBox新材质.Text = "";
            this.uiTextBox计量单位1.Text = "Kg";
            //this.uiComboBox去向.SelectedValue = form已发未完工卷.出库卷信息.NextWorkType;
            this.uiTextBox计划去向.Text = "";
            uiTextBox质量信息.Text = "";
            uiTextBox新重量.Text = "";
            uiTextBox新规格.Text = "";
            uiTextBox新重量.Text = "";
            uiTextBox轧制规格.Text = "";
            tempguid = Guid.NewGuid().ToString();
            this.uiDatePicker报工日期.Value = DateTime.Now;
          
         
            清理自己mac的Temp_彩涂报工原卷占用();

        }






        private void uiComboBox产线_SelectedIndexChanged(object sender, EventArgs e)
        {
            string workLineCode;
            if (this.uiComboBox产线.SelectedValue.ToString() != "")
            {
                workLineCode = this.uiComboBox产线.SelectedValue.ToString();
                pub.全局工厂编号 = pub.全局工厂编号;
                Dic_WorkLine dic_workline = pub.GetWorkLineByLineCode(pub.全局工厂编号, workLineCode);
                //if (dic_workline.DepartCode != null)
                //{
                //    Dic_Depart dic_depart = pub.GetDepartByCode(dic_workline.DepartCode, pub.全局工厂编号);
                //    if (dic_depart.DepartCode != "")
                //    {
                //        this.uiTextBox部门1.Text = dic_depart.DepartCode;
                //        this.uiTextBox部门名称1.Text = dic_depart.DepartName;
                //    }
                //    else
                //    {
                //        this.uiTextBox部门1.Text = "";
                //        this.uiTextBox部门名称1.Text = "";
                //    }
                //}
                //else
                //{
                //    this.uiTextBox部门1.Text = "";
                //    this.uiTextBox部门名称1.Text = "";
                //}

                this.uiComboBox仓库.SelectedValue = pub.根据产线获得仓库编号(this.uiComboBox产线.SelectedText);
                pub.ListWorkType(pub.全局工厂编号, FormWorkType, this.uiComboBox去向);
                //pub.ListWorkTeam(pub.全局工厂编号, workLineCode, this.uiComboBoxWorkTeam);
            }
        }

        private void uiTextBox新厚度_TextChanged(object sender, EventArgs e)
        {
            SetSize();
        }

        private void uiTextBox新宽度_TextChanged(object sender, EventArgs e)
        {
            //SetSize();
            刷新理算米数();
            刷新理算厚度();
        }
        private void SetSize()
        {
            this.uiTextBox新规格.Text = pub.Todecimal(this.uiTextBox新厚度.Text, 3) + "*" + (this.uiTextBox新宽度.Text) + "*C";
        }

        private void uiCheckBox拆成多卷_CheckedChanged(object sender, EventArgs e)
        {
            if (this.uiCheckBox拆成多卷.Checked)
            {
                this.numericUpDown1.Visible = true;
            }
            else
            {
                this.numericUpDown1.Visible = false;
            }
        }

        private void uiButton添加产出卷_Click(object sender, EventArgs e)
        {
            if (pub.Todecimal(this.uiTextBox卷重量1.Text)*pub.Todecimal(1.05) < 卷的总重量 + pub.Todecimal(this.uiTextBox新重量.Text))
            {
                MessageBox.Show("产出卷的重量超过了投入卷重量,不能单卷报工。", "提示", MessageBoxButtons.OK);
                return;
            }
            if (this.uiCheckBox拆成多卷.Checked == false)
            {
                //单卷
                //已经存在的就不能再次点击添加了
                if (!pub.Is彩涂报工原始卷被关闭(this.uiTextBox原料卷号.Text))
                {
                    string sql;
                    List<Bus_PaintOutput> bus_paintoriginals = pub.Get彩涂产出卷信息All(this.uiTextBox原料卷号.Text);
                    if (bus_paintoriginals != null)
                    {
                        MessageBox.Show("这个卷已经有产出卷了,不能单卷报工。", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    //if (MessageBox.Show("这卷不再分拆会自动关闭，是否确认?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    //{
                        单卷报工();
                    //}
                }
                else
                {
                    MessageBox.Show("这个卷已经被关闭了，不能再次报工了，如需要再次报工，请联系管理员处理。", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
            else
            {
                //单卷
                //已经存在的就不能再次点击添加了
                if (!pub.Is彩涂报工原始卷被关闭(this.uiTextBox原料卷号.Text))
                {

                    List<Bus_PaintOutput> bus_paintoutputs = pub.Get彩涂产出卷信息All(this.uiTextBox原料卷号.Text);
                    if (bus_paintoutputs != null)
                    {
                        bool s = false;
                        foreach (Bus_PaintOutput bus_paintoutput in bus_paintoutputs)
                        {
                            if (this.uiTextBox原料卷号.Text.Replace("PHD", "") == bus_paintoutput.OutputVolumeNew.Replace("PHC", ""))
                            {
                                s = true;
                            }
                        }
                        if (s)
                        {
                            MessageBox.Show("这个卷已经有产出单卷了,不能多卷报工。", "提示", MessageBoxButtons.OK);
                            return;
                        }

                    }
                    多卷报工();
                }
                else
                {
                    MessageBox.Show("这个卷已经被关闭了，不能再次报工了，如需要强制报工，请联系管理员处理。", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
        }

        private void 多卷报工()
        {
            if (彩涂原卷guid == "" || this.uiTextBox原料卷号.Text == "")
            {
                MessageBox.Show("没有选择投入卷号", "提示", MessageBoxButtons.OK);
                return;
            }
            string sql;

            string 新卷号;
            if (this.uiTextBox原料卷号.Text.IndexOf('/') > 0)
            {
                新卷号 = this.uiTextBox前缀.Text + this.uiTextBox产出卷号.Text + this.numericUpDown1.Value.ToString().PadLeft(2, '-');
            }
            else
            {
                新卷号 = this.uiTextBox前缀.Text + this.uiTextBox产出卷号.Text+  this.numericUpDown1.Value.ToString().PadLeft(2, '/');
            }

            

            Bus_PaintOutput bus_paintoutput = new Bus_PaintOutput();
            bus_paintoutput.Creator = pub.sys_user.UserName;
            bus_paintoutput.OutputDate = this.uiDatePicker报工日期.Value;
            if (this.uiComboBox去向.SelectedText == "")
            {
                MessageBox.Show("去向不能为空", "提示", MessageBoxButtons.OK);
                return;

            }
            if (pub.Get彩涂产出卷信息(新卷号) != null)
            {
                MessageBox.Show("产出卷号已经存在了，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.OutputNext = this.uiComboBox去向.SelectedText;
            bus_paintoutput.WorkLineName = this.uiComboBox产线.SelectedText;
            if (bus_paintoutput.WorkLineName == "")
            {
                MessageBox.Show("产线不能为空", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.WorkLineCode = this.uiComboBox产线.SelectedValue.ToString();
            bus_paintoutput.DayShiftCode = this.uiComboBoxDayShift.SelectedValue.ToString();
            bus_paintoutput.DayShiftName = this.uiComboBoxDayShift.SelectedText;
            
            bus_paintoutput.WorkTeamCode = this.uiComboBoxWorkTeam.SelectedText;

            bus_paintoutput.WorkTeamName = this.uiComboBoxWorkTeam.SelectedText;
            if (bus_paintoutput.WorkTeamName == "")
            {
                MessageBox.Show("班组不能为空", "提示", MessageBoxButtons.OK);
                return;
            }
            //bus_paintoutput.DepartCode = this.uiTextBox部门1.Text;
            //bus_paintoutput.DepartName = this.uiTextBox部门名称1.Text;
            //if (bus_paintoutput.DepartName == "")
            //{
            //    MessageBox.Show("部门不能为空", "提示", MessageBoxButtons.OK);
            //    return;
            //}
            bus_paintoutput.guid = Guid.Parse(彩涂原卷guid);
            bus_paintoutput.OutputGuid = Guid.NewGuid();
            bus_paintoutput.OutputMaterial = this.uiComboBox新材质.SelectedText;
            bus_paintoutput.OutputQualityGrade = this.uiComboBox质量等级.SelectedText;
            bus_paintoutput.OutputQualityInformation = this.uiTextBox质量信息.Text.Trim().Replace("--", "");
            bus_paintoutput.OutputSize = this.uiTextBox新规格.Text;
            bus_paintoutput.OutputThick = pub.Todecimal(uiTextBox新厚度.Text);
            bus_paintoutput.OutputWidth = uiTextBox新宽度.Text;
            bus_paintoutput.OutputWeight = pub.Todecimal(uiTextBox新重量.Text);
            if (bus_paintoutput.OutputWeight == 0)
            {
                MessageBox.Show("重量不能为0", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.OutputMeter = pub.Todecimal(uiTextBox新米数.Text);
            if (bus_paintoutput.OutputMeter == 0)
            {
                MessageBox.Show("米数不能为0", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.OutputAddress = this.uiTextBox产地1.Text;
            bus_paintoutput.OutputColor = this.uiComboBox颜色.Text.Trim().Replace("--", "");
            pub.UpdateColor(bus_paintoutput.OutputColor);
            if (bus_paintoutput.FaceDone == "")
            {
                MessageBox.Show("颜色不能为空", "提示", MessageBoxButtons.OK);
                return;
            }
            if (this.uiComboBox品名.Visible == true)
            {
                bus_paintoutput.InventoryName = uiComboBox品名.SelectedText;
                bus_paintoutput.InventoryCode = pub.GetInventoryCode(bus_paintoutput.InventoryName, bus_paintoutput.OutputSize, bus_paintoutput.OutputMaterial);
                if (bus_paintoutput.InventoryCode == "")
                {
                    MessageBox.Show("这个卷没有对应的NC存货编号", "提示", MessageBoxButtons.OK);
                }

                bus_paintoutput.QualityStandard = this.uiComboBox执行标准.SelectedText;
            }
            else
            {
                bus_paintoutput.InventoryName = "";
                bus_paintoutput.InventoryCode = "";
                bus_paintoutput.FaceDone = "";
                bus_paintoutput.QualityStandard = "";
            }
            pub.UpdateColor(bus_paintoutput.FaceDone);
            if (!this.uiComboBox品名.SelectedText.Contains("万都"))
            {


                ///验证理算厚度-分一下万都和万达
                if (!pub.彩涂符合万达理算厚度(pub.Todecimal(this.uiTextBox新厚度.Text), pub.Todecimal(this.uiTextBox理算厚度.Text)))
                {
                    if (MessageBox.Show("这个卷的理算厚度和成品厚度有问题，是否需要添加？", "询问", MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }

                }
            }
            else
            {
                if (!pub.彩涂符合万都理算厚度(pub.Todecimal(this.uiTextBox新厚度.Text), pub.Todecimal(this.uiTextBox理算厚度.Text)))
                {
                    if (MessageBox.Show("这个卷的理算厚度和成品厚度有问题，是否需要添加？", "询问", MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }

                }
            }
            sql = " insert into Bus_PaintOutput(OutputGuid,guid,OutputDate,  VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick,";
            sql +=" OutputWidth, OutputMaterial, OutputWeight, OutputMeter,";
            sql += " OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, ";
            sql += " WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator,";
            sql += " CreateDate,OutputAddress,FaceDone,InventoryName,InventoryCode,QualityStandard,OutputColor,[Customer] ,[Package], [ZincThick] ,[LisuanThick] ,[LisuanMeter],memo)";
            sql += " values(newid(),'" + 彩涂原卷guid + "','"+ bus_paintoutput.OutputDate + "','" + this.uiTextBox原料卷号.Text.Trim().Replace("--", "") + "','" + this.numericUpDown1.Value.ToString() + "','" + 新卷号 + "','" + bus_paintoutput.OutputSize + "','" + bus_paintoutput.OutputThick + "','" + bus_paintoutput.OutputWidth + "',";
            sql += " '" + bus_paintoutput.OutputMaterial + "','" + bus_paintoutput.OutputWeight + "','" + bus_paintoutput.OutputMeter + "','" + bus_paintoutput.OutputQualityGrade + "','" + bus_paintoutput.OutputQualityInformation + "',";
            sql += "  '','" + bus_paintoutput.OutputNext + "',0,'" + bus_paintoutput.DepartCode + "','" + bus_paintoutput.DepartName + "',";
            sql += " '" + bus_paintoutput.WorkLineCode + "','" + bus_paintoutput.WorkLineName + "','" + bus_paintoutput.WorkTeamCode + "','" + bus_paintoutput.WorkTeamName + "',";
            sql += " '" + bus_paintoutput.DayShiftCode + "','" + bus_paintoutput.DayShiftName + "','" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',";
            sql += " getdate(),'" + bus_paintoutput.OutputAddress + "','" + bus_paintoutput.FaceDone + "','" + bus_paintoutput.InventoryName + "','" + bus_paintoutput.InventoryCode + "',";
            sql += " '" + bus_paintoutput.QualityStandard + "','" + bus_paintoutput.OutputColor + "','"+ uiTextBox客户.Text + "','"+ uiComboBox包装.SelectedText+ "','"+ uiTextBox锌层.Text+ "','"+ uiTextBox理算厚度.Text+ "','"+ uiTextBox理算米数.Text+ "','"+ uiTextBox备注.Text.Trim()+ "')";
            if (pub.ExecuteSql(pub.ConnectionString, sql, "多卷彩涂报工塞入bus_paintoutput") > 0)
            {
                MessageBox.Show("多卷彩涂报工成功", "提示", MessageBoxButtons.OK);
                //不用自动关闭
                //sql = "update Bus_PicklingOriginal set IsClosed='Y' , ColseUserId='" + pub.sys_user.User_Id + "',ColseUserName='" + pub.sys_user.UserTrueName + "',CloseDate=getdate() where guid='" + 彩涂原卷guid + "'";
                //pub.ExecuteSql(pub.ConnectionString, sql, "单卷彩涂报工成功，自动关闭原卷的状态");
                if (this.uiTextBox原料卷号.Text.Contains("PHD"))
                {
                    sql = "update Bus_ZincOutput set OutputEndStatus='已被彩涂' where OutputVolumeNew='" + this.uiTextBox原料卷号.Text + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "彩涂报工改写镀锌产出卷状态");
                }
               
                //显示卷信息到表格上
                ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
                return;
            }
        }

        private void 单卷报工()
        {
            if (彩涂原卷guid == "" || this.uiTextBox原料卷号.Text == "")
            {
                MessageBox.Show("没有选择投入卷号", "提示", MessageBoxButtons.OK);
                return;
            }
            string sql;
            string 新卷号;
            if (this.uiTextBox原料卷号.Text.IndexOf('/')>0)
            {
                新卷号 = this.uiTextBox前缀.Text + this.uiTextBox产出卷号.Text;
            }
            else
            {
                新卷号 = this.uiTextBox前缀.Text + this.uiTextBox产出卷号.Text + "/1";
            }
            

            Bus_PaintOutput bus_paintoutput = new Bus_PaintOutput();
            bus_paintoutput.Creator = pub.sys_user.UserName;
            bus_paintoutput.OutputDate = this.uiDatePicker报工日期.Value;
            if (this.uiComboBox去向.SelectedText == "")
            {
                MessageBox.Show("去向不能为空", "提示", MessageBoxButtons.OK);
                return;

            }
            if (pub.Get彩涂产出卷信息(新卷号) != null)
            {
                MessageBox.Show("产出卷号已经存在了，不能添加", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.OutputNext = this.uiComboBox去向.SelectedText;
            bus_paintoutput.WorkLineName = this.uiComboBox产线.SelectedText;
            if (bus_paintoutput.WorkLineName == "")
            {
                MessageBox.Show("产线不能为空", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.WorkLineCode = this.uiComboBox产线.SelectedValue.ToString();
            bus_paintoutput.DayShiftCode = this.uiComboBoxDayShift.SelectedValue.ToString();
            bus_paintoutput.DayShiftName = this.uiComboBoxDayShift.SelectedText;

            bus_paintoutput.WorkTeamCode = this.uiComboBoxWorkTeam.SelectedText;

            bus_paintoutput.WorkTeamName = this.uiComboBoxWorkTeam.SelectedText;
            if (bus_paintoutput.WorkTeamName == "")
            {
                MessageBox.Show("班组不能为空", "提示", MessageBoxButtons.OK);
                return;
            }
            //bus_paintoutput.DepartCode = this.uiTextBox部门1.Text;
            //bus_paintoutput.DepartName = this.uiTextBox部门名称1.Text;
            //if (bus_paintoutput.DepartName == "")
            //{
            //    MessageBox.Show("部门不能为空", "提示", MessageBoxButtons.OK);
            //    return;
            //}
            bus_paintoutput.guid = Guid.Parse(彩涂原卷guid);
            bus_paintoutput.OutputGuid = Guid.NewGuid();
            bus_paintoutput.OutputMaterial = this.uiComboBox新材质.SelectedText;
            bus_paintoutput.OutputQualityGrade = this.uiComboBox质量等级.SelectedText;
            bus_paintoutput.OutputQualityInformation = this.uiTextBox质量信息.Text.Trim().Replace("--", "");
            bus_paintoutput.OutputSize = this.uiTextBox新规格.Text;
            bus_paintoutput.OutputThick = pub.Todecimal(uiTextBox新厚度.Text);
            bus_paintoutput.OutputWidth = uiTextBox新宽度.Text;
            bus_paintoutput.OutputWeight = pub.Todecimal(uiTextBox新重量.Text);
            if (bus_paintoutput.OutputWeight == 0)
            {
                MessageBox.Show("重量不能为0", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.OutputMeter = pub.Todecimal(uiTextBox新米数.Text);
            if (bus_paintoutput.OutputMeter == 0)
            {
                MessageBox.Show("米数不能为0", "提示", MessageBoxButtons.OK);
                return;
            }
            bus_paintoutput.OutputAddress = this.uiTextBox产地1.Text;
            bus_paintoutput.OutputColor = this.uiComboBox颜色.Text;
            pub.UpdateColor(bus_paintoutput.OutputColor);
            if (bus_paintoutput.FaceDone == "")    
            {
                MessageBox.Show("颜色不能为空", "提示", MessageBoxButtons.OK);
                return;
            }
            if (this.uiComboBox品名.Visible == true)
            {
                bus_paintoutput.InventoryName = uiComboBox品名.SelectedText;
                bus_paintoutput.InventoryCode = pub.GetInventoryCode(bus_paintoutput.InventoryName, bus_paintoutput.OutputSize, bus_paintoutput.OutputMaterial);
                if (bus_paintoutput.InventoryCode == "")
                {
                    MessageBox.Show("这个卷没有对应的NC存货编号", "提示", MessageBoxButtons.OK);
                }

                bus_paintoutput.QualityStandard = this.uiComboBox执行标准.SelectedText;
            }
            else
            {
                bus_paintoutput.InventoryName = "";
                bus_paintoutput.InventoryCode = "";
                bus_paintoutput.FaceDone = "";
                bus_paintoutput.QualityStandard = "";
            }
            pub.UpdateColor(bus_paintoutput.FaceDone);
            if (!this.uiComboBox品名.SelectedText.Contains("万都"))
            {


                ///验证理算厚度-分一下万都和万达
                if (!pub.彩涂符合万达理算厚度(pub.Todecimal(this.uiTextBox新厚度.Text), pub.Todecimal(this.uiTextBox理算厚度.Text)))
                {
                    if (MessageBox.Show("这个卷的理算厚度和成品厚度有问题，是否需要添加？", "询问", MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }

                }
            }
            else
            {
                if (!pub.彩涂符合万都理算厚度(pub.Todecimal(this.uiTextBox新厚度.Text), pub.Todecimal(this.uiTextBox理算厚度.Text)))
                {
                    if (MessageBox.Show("这个卷的理算厚度和成品厚度有问题，是否需要添加？", "询问", MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }

                }
            }
           


            sql = " insert into Bus_PaintOutput(OutputGuid, guid,OutputDate, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,";
            sql += " OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, ";
            sql += " WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator,";
            sql += " CreateDate,OutputAddress,FaceDone,InventoryName,InventoryCode,QualityStandard,OutputColor,[Customer] ,[Package], [ZincThick] ,[LisuanThick] ,[LisuanMeter],memo)";
            sql += " values(newid(),'" + 彩涂原卷guid + "','" + bus_paintoutput.OutputDate + "','" + this.uiTextBox原料卷号.Text.Trim().Replace("--", "") + "','" + this.numericUpDown1.Value.ToString() + "','" + 新卷号 + "','" + bus_paintoutput.OutputSize + "','" + bus_paintoutput.OutputThick + "','" + bus_paintoutput.OutputWidth + "',";
            sql += " '" + bus_paintoutput.OutputMaterial + "','" + bus_paintoutput.OutputWeight + "','" + bus_paintoutput.OutputMeter + "','" + bus_paintoutput.OutputQualityGrade + "','" + bus_paintoutput.OutputQualityInformation + "',";
            sql += "  '','" + bus_paintoutput.OutputNext + "',0,'" + bus_paintoutput.DepartCode + "','" + bus_paintoutput.DepartName + "',";
            sql += " '" + bus_paintoutput.WorkLineCode + "','" + bus_paintoutput.WorkLineName + "','" + bus_paintoutput.WorkTeamCode + "','" + bus_paintoutput.WorkTeamName + "',";
            sql += " '" + bus_paintoutput.DayShiftCode + "','" + bus_paintoutput.DayShiftName + "','" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',";
            sql += " getdate(),'" + bus_paintoutput.OutputAddress + "','" + bus_paintoutput.FaceDone + "','" + bus_paintoutput.InventoryName + "','" + bus_paintoutput.InventoryCode + "',";
            sql += " '" + bus_paintoutput.QualityStandard + "','" + bus_paintoutput.OutputColor +"','"+ uiTextBox客户.Text + "','"+ uiComboBox包装.SelectedText+ "','"+ uiTextBox锌层.Text+ "','"+ uiTextBox理算厚度.Text+ "','"+ uiTextBox理算米数.Text+ "','"+ uiTextBox备注.Text.Trim()+ "')";

            if (pub.ExecuteSql(pub.ConnectionString, sql, "单卷彩涂报工塞入bus_paintoutput") > 0)
            {
                MessageBox.Show("单卷彩涂报工成功", "提示", MessageBoxButtons.OK);
                //sql = "update bus_paintoriginal set IsClosed='Y' , ColseUserId='" + pub.sys_user.User_Id + "',ColseUserName='" + pub.sys_user.UserTrueName + "',CloseDate=getdate() where guid='" + 彩涂原卷guid + "'";
                //pub.ExecuteSql(pub.ConnectionString, sql, "单卷彩涂报工成功，自动关闭原卷的状态");
                if (this.uiTextBox原料卷号.Text.Contains("PHD"))
                {
                    sql = "update Bus_ZincOutput set OutputEndStatus='已被彩涂' where OutputVolumeNew='" + this.uiTextBox原料卷号.Text + "'";
                    pub.ExecuteSql(pub.ConnectionString, sql, "彩涂报工改写镀锌产出卷状态");
                }
                //显示卷信息到表格上
                ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
                return;
            }
        }
        private void ListOutput(string 投入卷号)
        {
            卷的总重量 = 0;
            string 查询投入卷号 = "PHD" + 投入卷号.Replace("PHD", "");  //只查卷号的7位纯数字
            string sql;
            sql = "SELECT   OutputGuid,VolumeCodeNew, OutputDate 报工日期,guid, Row, OutputVolumeNew 新卷号, OutputSize 新规格, OutputThick 新厚度, OutputWidth 新宽度, ";
            sql += " OutputMaterial 新材质, OutputWeight 新重量,OutputMeter 新米数,OutputQualityGrade 质量等级, OutputQualityInformation 质量信息, OutputEndStatus 后续状态,";
            sql += " OutputNext 去向,InventoryCode 存货编号,InventoryName 品名, FaceDone 表面处理, FaceStatus 表面状态,QualityStandard 执行标准,";
            sql += " PrintTimes 打印次数, DepartCode 部门编号, DepartName 生产部门,  WorkLineCode 产线编号, WorkLineName 产线, WorkTeamCode 班组编号, WorkTeamName 班组,";
            sql += " DayShiftCode 班别编号, DayShiftName 班别, CreateID, Creator 填报人,  CreateDate 填报时间, ModifyID, Modifier, ModifyDate,OutputColor,memo 备注 ";
            sql += " FROM      Bus_PaintOutput where VolumeCodeNew='" + 查询投入卷号 + "' order by OutputVolumeNew ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                uiDataGridView产出.AutoGenerateColumns = false;
                this.uiDataGridView产出.DataSource = tb;
                this.uiDataGridView产出.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;
                this.uiDataGridView产出.Refresh();
                //产出卷必须连号,不连号不行。
                if (tb.Rows.Count > 0)
                {
                    if (tb.Rows.Count == 1)
                    {
                        卷的总重量 = pub.Todecimal(tb.Rows[0]["新重量"].ToString());
                        //只有一卷
                    }
                    else
                    {
                        for (int i = 0; i < tb.Rows.Count; i++)
                        {
                            卷的总重量 += pub.Todecimal(tb.Rows[i]["新重量"].ToString());
                            //if (this.uiTextBox前缀.Text + uiTextBox产出卷号.Text + (i + 1).ToString().PadLeft(2, '-') != tb.Rows[i]["新卷号"].ToString())
                            //{
                            //    MessageBox.Show("产出的卷号不连号请检查", "提示", MessageBoxButtons.OK);
                            //}
                        }
                    }

                }
            }

            //背景色
            for (int i = 0; i < this.uiDataGridView产出.Rows.Count; i++)
            {
                if (this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Value.ToString() == "B")
                {
                    this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Style.BackColor = Color.FromArgb(255, 255, 128);
                }
                else if (this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Value.ToString() == "S")
                {
                    this.uiDataGridView产出.Rows[i].Cells["C质量等级"].Style.BackColor = Color.FromArgb(255, 0, 0);
                }
            }


            //显示是否关闭了。
            sql = "select IsClosed from [bus_paintoriginal] where OriginalVolumeNew='" + 投入卷号 + "' ";
            DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb2 != null)
            {
                if (tb2.Rows.Count > 0)
                {
                    if (tb2.Rows[0]["IsClosed"].ToString() == "Y")
                    {
                        this.uiLabelIsClosed.Text = "已关闭";
                    }
                    else
                    {
                        this.uiLabelIsClosed.Text = "未关闭";
                    }
                }
            }

        }

        private void Form彩涂报工维护_FormClosed(object sender, FormClosedEventArgs e)
        {
            删除自己的tempguid的数据(tempguid);
        }

        private void uiDataGridView产出_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.uiDataGridView产出.Rows.Count > 0)
            {
                if (this.uiDataGridView产出.Columns[e.ColumnIndex].Name == "C删除")
                {
                    if (!pub.Is彩涂报工原始卷被关闭(this.uiTextBox原料卷号.Text))
                    {

                        string 彩涂产出卷号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新卷号"].Value.ToString();
                        string 后续状态 = pub.Get彩涂产出卷的后续状态(彩涂产出卷号);
                        if (后续状态 != "未使用")
                        {
                            MessageBox.Show("这个卷状态有问题了", "提示", MessageBoxButtons.OK);
                            //显示卷信息到表格上
                            // this.uiDataGridView产出.Rows[e.RowIndex].Cells["C后续状态"].Value = 后续状态;
                            ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
                            return;
                        }
                        else
                        {   //本人才能删除
                            string 填报人 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C填报人"].Value.ToString();
                            if (填报人 != pub.sys_user.UserTrueName)
                            {
                                MessageBox.Show("您不可以删除其他人员填报的数据", "提示", MessageBoxButtons.OK);
                                return;
                            }
                            if (MessageBox.Show("你要删除这个产出卷么?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                //检查是否打印打标签了
                                if (pub.产出卷是否打印入库(彩涂产出卷号))
                                {
                                    MessageBox.Show("【"+ 彩涂产出卷号 + "】已经打印大标签入库，无法删除");
                                    return;
                                }
                                
                                string sql = "delete Bus_PaintOutput where OutputVolumeNew='" + 彩涂产出卷号 + "';";
                                sql += "delete from Bus_LablePrint where 生产批号 = '" + 彩涂产出卷号 + "';";
                                pub.ExecuteSql(pub.ConnectionString, sql, "删除产出的彩涂卷");
                                //原卷的状态还原
                                sql = "update bus_paintoriginal set IsClosed='N' , ColseUserId=NULL,ColseUserName=NULL,CloseDate=NULL where guid='" + 彩涂原卷guid + "'";
                                pub.ExecuteSql(pub.ConnectionString, sql, "单卷彩涂报工取消成功，自动开启原卷的状态");

                                ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
                            }

                        }
                    }
                    else
                    {
                        MessageBox.Show("已经关闭的投入卷不能删除产出卷信息", "提示", MessageBoxButtons.OK);
                        ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
                        return;
                    }
                }
                else if (this.uiDataGridView产出.Columns[e.ColumnIndex].Name == "C打印小标签" && this.uiDataGridView产出.Rows[e.RowIndex].Cells["C去向"].Value.ToString()=="下线入库")
                {
                    Form小标签 form小标签 = new Form小标签();
                    form小标签.生产批号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新卷号"].Value.ToString();
                    form小标签.规格 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新规格"].Value.ToString();
                    form小标签.钢号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新材质"].Value.ToString();
                    form小标签.等级 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C质量等级"].Value.ToString();
                    form小标签.净重 = Math.Round(pub.Todecimal(this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新重量"].Value.ToString()), 0).ToString();
                    form小标签.工厂编号 = pub.全局工厂编号;
                    form小标签.来源种类 = "彩涂小标签";
                    form小标签.存货编号 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C存货编号"].Value.ToString();
                    form小标签.品名 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C品名"].Value.ToString();
                    form小标签.表面处理 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C表面处理"].Value.ToString();
                    form小标签.表面状态 = "";
                    form小标签.颜色= this.uiDataGridView产出.Rows[e.RowIndex].Cells["C颜色"].Value.ToString();
                    form小标签.执行标准 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C执行标准"].Value.ToString();
                    form小标签.长度 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C新米数"].Value.ToString(); ;
                    form小标签.生产日期 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C报工日期"].Value.ToString();
                    form小标签.班组 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C班组"].Value.ToString();
                    form小标签.产线名称 = this.uiDataGridView产出.Rows[e.RowIndex].Cells["C产线"].Value.ToString();
                    form小标签.仓库 = this.uiComboBox仓库.SelectedValue.ToString();
                    form小标签.锌层 = this.uiTextBox锌层.Text;
                    form小标签.客户 = this.uiTextBox客户.Text;
                    form小标签.包装 = uiComboBox包装.SelectedText;
                    form小标签.ShowDialog(this);
                }
            }
        }

        private void uiButton关闭_Click(object sender, EventArgs e)
        {
            string sql;
            //产出卷必须连号
            sql = "SELECT   OutputGuid, guid, Row, OutputVolumeNew 新卷号, OutputSize 新规格, OutputThick 新厚度, OutputWidth 新宽度, OutputMaterial 新材质, OutputWeight 新重量, OutputQualityGrade 质量等级, OutputQualityInformation 质量信息, OutputEndStatus 后续状态, OutputNext 去向,";
            sql += " PrintTimes 打印次数, DepartCode 部门编号, DepartName 生产部门,  WorkLineCode 产线编号, WorkLineName 产线, WorkTeamCode 班组编号, WorkTeamName 班组, DayShiftCode 班别编号, DayShiftName 班别, CreateID, Creator 填报人,  CreateDate 填报时间, ModifyID, Modifier, ModifyDate ";
            sql += " FROM      Bus_PaintOutput where guid='" + 彩涂原卷guid + "' order by OutputVolumeNew ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                uiDataGridView产出.AutoGenerateColumns = false;
                this.uiDataGridView产出.DataSource = tb;
                this.uiDataGridView产出.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;
                this.uiDataGridView产出.Refresh();
                //产出卷必须连号,不连号不行。
                if (tb.Rows.Count > 0)
                {
                    if (tb.Rows.Count == 1)
                    {
                        //只有一卷
                    }
                    else
                    {
                        for (int i = 0; i < tb.Rows.Count; i++)
                        {
                            if (this.uiTextBox前缀.Text + uiTextBox产出卷号.Text + (i + 1).ToString().PadLeft(2, '-') != tb.Rows[i]["新卷号"].ToString())
                            {
                                MessageBox.Show("产出的卷号不连号请检查", "提示", MessageBoxButtons.OK);
                                return;
                            }
                        }
                    }

                }
            }


            if (MessageBox.Show("你要关闭这个投入卷么?", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                sql = "update bus_paintoriginal set IsClosed='Y' , ColseUserId='" + pub.sys_user.User_Id + "',ColseUserName='" + pub.sys_user.UserTrueName + "',CloseDate=getdate() where guid='" + 彩涂原卷guid + "'";
                pub.ExecuteSql(pub.ConnectionString, sql, "彩涂手动关闭原卷的状态");
                ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
            }
        }

        private void uiTextBox原料卷号_KeyPress(object sender, KeyPressEventArgs e)
        {
            //if (e.KeyChar == 13)
            //{
            //    Bus_HardOriginal bus_hardoriginal = pub.Get彩涂投入信息(pub.全局工厂编号, this.uiTextBox原料卷号.Text);
            //        if (bus_hardoriginal!=null)
            //        {
            //        彩涂原卷guid = bus_hardoriginal.guid.ToString();
            //        this.uiTextBox产出卷号.Text = pub.去掉前缀(this.uiTextBox原料卷号.Text);//不含前缀，不含后面的串号
            //        uiTextBox规格型号1.Text = bus_hardoriginal.OriginalSize;
            //        string 厚度 = "";
            //        string 宽度 = "";
            //        string 虚拟值 = "";
            //        pub.FromSize(uiTextBox规格型号1.Text, out 厚度, out 宽度, out 虚拟值);
            //        this.uiTextBox厚度1.Text = 厚度;
            //        this.uiTextBox宽度1.Text = 宽度;
            //        this.uiTextBox新厚度.Text = 厚度;
            //        this.uiTextBox新宽度.Text = 宽度;
            //        this.uiTextBox卷重量1.Text = bus_hardoriginal.OriginalWeight.ToString();
            //        this.uiTextBox材质1.Text = bus_hardoriginal.OriginalMaterial;
            //        this.uiTextBox米数.Text = bus_hardoriginal.OriginalMeter.ToString();
            //        this.uiComboBox新材质.Text = this.uiTextBox材质1.Text;
            //        this.uiTextBox计量单位1.Text = "Kg";
            //        ListHardOutput(彩涂原卷guid);
            //        塞入自己的tempguid的数据(tempguid, bus_hardoriginal.OriginalVolumeNew);


            //}








        }
      


        private void uiLabel18_Click(object sender, EventArgs e)
        {

        }

        private void uiButton搜索已生产卷_Click(object sender, EventArgs e)
        {
            List已生产卷();
        }

        private void List已生产卷()
        {

           string  用来保存的原卷号 = "";
            Bus_PaintOriginal bus_paintoriginal = pub.Get彩涂投入信息(pub.全局工厂编号, this.uiTextBox原料卷号.Text,out 用来保存的原卷号);
            if (bus_paintoriginal != null)
            {
                彩涂原卷guid = bus_paintoriginal.guid.ToString();
                this.uiTextBox原料卷号.Text = 用来保存的原卷号;
                this.uiTextBox产出卷号.Text = pub.去掉前缀(this.uiTextBox原料卷号.Text);//不含前缀，不含后面的串号
                uiTextBox规格型号1.Text = bus_paintoriginal.OriginalSize;
                string 厚度 = "";
                string 宽度 = "";
                string 虚拟值 = "";
                pub.FromSize(uiTextBox规格型号1.Text, out 厚度, out 宽度, out 虚拟值);
                this.uiTextBox厚度1.Text = 厚度;
                this.uiTextBox宽度1.Text = 宽度;
                this.uiTextBox新厚度.Text = 厚度;
                this.uiTextBox新宽度.Text = 宽度;
                uiTextBox成品宽度.Text = 宽度;
                uiTextBox新规格.Text = uiTextBox规格型号1.Text;
                this.uiTextBox卷重量1.Text = bus_paintoriginal.OriginalWeight.ToString();
                this.uiTextBox材质1.Text = bus_paintoriginal.OriginalMaterial;
                this.uiTextBox米数.Text = bus_paintoriginal.OriginalMeter.ToString();
                this.uiComboBox新材质.Text = this.uiTextBox材质1.Text;
                this.uiTextBox产地1.Text = bus_paintoriginal.OriginalAddress;
                this.uiTextBox计量单位1.Text = "Kg";
                ListOutput(this.uiTextBox原料卷号.Text.Trim().Replace("--", ""));
              
                塞入自己的tempguid的数据(tempguid, bus_paintoriginal.OriginalVolumeNew);
            }
            else
            {
                MessageBox.Show("没有投入的卷信息，请先选择投入卷 " + this.uiTextBox原料卷号.Text, "提示", MessageBoxButtons.OK);
                return;
            }
        }
       


        private void uiButtonClearAll_Click(object sender, EventArgs e)
        {
            CleallAll();
        }

        private void uiLabel11_Click(object sender, EventArgs e)
        {

        }

        private void uiComboBox去向_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.uiComboBox去向.SelectedText == "下线入库")
            {
                this.uiLabel颜色.Visible = true;
                this.uiComboBox执行标准.Visible = true;
                this.uiLabel执行标准.Visible = true;
                this.uiComboBox颜色.Visible = true;
                this.uiLabel品名.Visible = true;
                this.uiComboBox品名.Visible = true;
                uiLabel包装.Visible = true;
                uiComboBox包装.Visible = true;
            }
            else
            {
                this.uiLabel颜色.Visible = true;
                this.uiComboBox执行标准.Visible = true;
                this.uiLabel执行标准.Visible = true;
                this.uiComboBox颜色.Visible = true;
                this.uiLabel品名.Visible = true;
                this.uiComboBox品名.Visible = true;
                uiLabel包装.Visible = false;
                uiComboBox包装.Visible = false;
            }
        }

        private void uiComboBox质量等级_SelectedIndexChanged(object sender, EventArgs e)
        {
            pub.List品名(this.uiComboBox品名, FormWorkType, this.uiComboBox质量等级.SelectedText);
        }

        private void uiButton投入查询_Click(object sender, EventArgs e)
        {
            ListData();
        }

        private void ListData()
        {
            string sql;
            sql = @"SELECT row_number() over(order by  时间,卷号 ) 序号,   工厂编号, 时间, 卷号, 规格型号, 计划产出规格,材质, 重量,产地, 米数, 质量等级, 质量信息,成品规格,计划去向,锌层  FROM      View_已镀锌未彩涂 where 1=1  ";
            sql += " and 工厂编号='" + pub.全局工厂编号 + "'";
           
            if (this.uiTextBox查询材质.Text != "")
            {
                sql += " and 材质 ='" + this.uiTextBox查询材质.Text.Trim().Replace("--", "") + "'";
            }
            if (this.uiTextBox查询规格型号.Text.Trim() != "")
            {
                sql += " and 规格型号 ='" + this.uiTextBox查询规格型号.Text.Trim().Replace("--", "") + "'";
            }

            if (this.uiTextBox查询成品规格.Text.Trim() != "")
            {
                sql += " and 成品规格 ='" + this.uiTextBox查询成品规格.Text.Trim().Replace("--", "") + "'";
            }

            if (this.uiTextBox查询卷号.Text.Trim() != "")
            {
                sql += " and 卷号 like '%" + this.uiTextBox查询卷号.Text.Trim().Replace("--", "") + "%'";
            }
            if (this.uiTextBox查询客户.Text.Trim() != "")
            {
                sql += " and 客户 = '" + this.uiTextBox查询客户.Text.Trim().Replace("--", "") + "'";
            }
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                this.uiDataGridView可用.AutoGenerateColumns = false;
                this.uiDataGridView可用.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView可用.DataSource = tb;
                this.uiDataGridView可用.Refresh();
            }
            else
            {
                this.uiDataGridView可用.DataSource = null;
                this.uiDataGridView可用.Refresh();
                MessageBox.Show("没有已镀锌未彩涂的卷可以选择", "提示", MessageBoxButtons.OK);
                return;

            }
        }

        private void uiDataGridView可用_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && this.uiDataGridView可用.Columns[e.ColumnIndex].Name == "D选择")
            {
                this.uiTextBox新重量.Text = "";
                this.uiTextBox新米数.Text = "";
                this.uiTextBox原料卷号.Text = this.uiDataGridView可用.Rows[e.RowIndex].Cells["D卷号"].Value.ToString();
                if (string.IsNullOrEmpty(this.uiDataGridView可用.Rows[e.RowIndex].Cells["D锌层"].Value.ToString()))
                {
                    this.uiTextBox锌层.Text = "普通";
                }
                else
                {
                    this.uiTextBox锌层.Text = uiDataGridView可用.Rows[e.RowIndex].Cells["D锌层"].Value.ToString();
                }
               
                彩涂原卷guid = pub.Get彩涂报工guid(this.uiTextBox原料卷号.Text);
                List已生产卷();
            }
        }

        private void uiTextBox新重量_TextChanged(object sender, EventArgs e)
        {
            刷新理算米数();
            刷新理算厚度();
        }

        private void 刷新理算厚度()
        {
            //分支
            if (this.uiComboBox品名.SelectedText.Contains("万都"))
            {
                刷新万都理算厚度();
            }
            else
            {
                刷新万达理算厚度();
            }
        }

        private void 刷新万达理算厚度()
        {
            double 手填重量;

            手填重量 = pub.Todouble(this.uiTextBox新重量.Text);
            double 手填宽度;
            手填宽度 = pub.Todouble(this.uiTextBox新宽度.Text);
            //double 手填厚度;
            //手填厚度 = pub.Todouble(this.uiTextBox新宽度.Text);
            double 手填米数;
            手填米数 = pub.Todouble(this.uiTextBox新米数.Text);
            if (手填重量 > 0 && 手填宽度 > 0 && 手填米数 > 0)
            {
                this.uiTextBox理算厚度.Text = Math.Round((手填重量 / (手填宽度 / 1000) / 手填米数 / 7.85), 4).ToString();
            }
            else
            {
                this.uiTextBox理算厚度.Text = "";
            }
        }

        private void 刷新万都理算厚度()
        {
            double 手填重量;

            手填重量 = pub.Todouble(this.uiTextBox新重量.Text);
            double 手填宽度;
            手填宽度 = pub.Todouble(this.uiTextBox新宽度.Text);
            //double 手填厚度;
            //手填厚度 = pub.Todouble(this.uiTextBox新宽度.Text);
            double 手填米数;
            手填米数 = pub.Todouble(this.uiTextBox新米数.Text);
            if (手填重量 > 0 && 手填宽度 > 0 && 手填米数 > 0)
            {
                this.uiTextBox理算厚度.Text = Math.Round((手填重量 / (手填宽度 / 1000) / 手填米数 / 7.85), 4).ToString();
            }
            else
            {
                this.uiTextBox理算厚度.Text = "";
            }
        }

        private void 刷新理算米数()
        {
            double 手填重量;

            手填重量 = pub.Todouble(this.uiTextBox新重量.Text);
            double 手填宽度;
            手填宽度 = pub.Todouble(this.uiTextBox新宽度.Text);
            double 手填厚度;
            手填厚度 = pub.Todouble(this.uiTextBox新厚度.Text);
            //decimal 手填米数;
            //手填米数 = pub.Todecimal(this.uiTextBox新米数.Text);
            if (手填重量 > 0 && 手填宽度 > 0 && 手填厚度 > 0)
            {
                this.uiTextBox理算米数.Text = Math.Round((手填重量 / (手填宽度 / 1000) / 手填厚度 / 7.85), 4).ToString();
            }
            else
            {
                this.uiTextBox理算米数.Text = "";
            }
        }

        private void uiTextBox新米数_TextChanged(object sender, EventArgs e)
        {
            刷新理算米数();
            刷新理算厚度();
        }

        private void uiComboBox品名_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (uiComboBox品名.Text.Contains("镀锌"))
            {
                pub.ListQualityStandard("镀锌", this.uiComboBox执行标准);
                this.uiTextBox前缀.Text = "PHD";
            }
            else
            {
                pub.ListQualityStandard("彩涂", this.uiComboBox执行标准);
                this.uiTextBox前缀.Text = "PHC";
            }
        }

        private void uiDataGridView产出_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string C新卷号 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新卷号"].Value.ToString();
            string C报工日期 = uiDataGridView产出.Rows[e.RowIndex].Cells["C报工日期"].Value.ToString();
            string C新规格 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新规格"].Value.ToString();
            string C新厚度 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新厚度"].Value.ToString();
            string C新宽度 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新宽度"].Value.ToString();
            string C新重量 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新重量"].Value.ToString();
            string C新材质 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新材质"].Value.ToString();
            string C新米数 = uiDataGridView产出.Rows[e.RowIndex].Cells["C新米数"].Value.ToString();
            string C质量等级 = uiDataGridView产出.Rows[e.RowIndex].Cells["C质量等级"].Value.ToString();
            string C备注 = uiDataGridView产出.Rows[e.RowIndex].Cells["C备注"].Value.ToString();
            string C产线 = uiDataGridView产出.Rows[e.RowIndex].Cells["C产线"].Value.ToString();
            string C班组 = uiDataGridView产出.Rows[e.RowIndex].Cells["C班组"].Value.ToString();
            string C班别 = uiDataGridView产出.Rows[e.RowIndex].Cells["C班别"].Value.ToString();
            string C去向 = uiDataGridView产出.Rows[e.RowIndex].Cells["C去向"].Value.ToString();
            string C后续状态 = uiDataGridView产出.Rows[e.RowIndex].Cells["C后续状态"].Value.ToString();
            string C质量信息 = uiDataGridView产出.Rows[e.RowIndex].Cells["C质量信息"].Value.ToString();
            string C品名 = uiDataGridView产出.Rows[e.RowIndex].Cells["C品名"].Value.ToString();
            string C执行标准 = uiDataGridView产出.Rows[e.RowIndex].Cells["C执行标准"].Value.ToString();
            string C颜色 = uiDataGridView产出.Rows[e.RowIndex].Cells["C颜色"].Value.ToString();
            string 填报人 = uiDataGridView产出.Rows[e.RowIndex].Cells["C填报人"].Value.ToString();

            //查询卷号有没有打印过
            string 后续状态 = pub.Get彩涂产出卷的后续状态(C新卷号);
            if (后续状态 != "未使用")
            {
                MessageBox.Show("这个卷状态:" + 后续状态, "提示", MessageBoxButtons.OK);
                //显示卷信息到表格上
                // this.uiDataGridView产出.Rows[e.RowIndex].Cells["C后续状态"].Value = 后续状态;
                ListOutput(this.uiTextBox原料卷号.Text);
                return;
            }
            else
            {   //本人才能删除

                if (填报人 != pub.sys_user.UserTrueName && pub.sys_user.UserTrueName != "超级管理员")
                {
                    MessageBox.Show("您不可以修改其他人员填报的数据", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (MessageBox.Show("你要修改这个产出卷么？数据需要填正确哦！", "询问", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    string sql = "update Bus_PaintOutput set OutputDate = '" + C报工日期 + "',OutputSize = '"+ C新规格 + "',OutputThick = '"+ C新厚度 + "',";
                    sql += "OutputWidth = '" + C新宽度 + "',OutputMaterial ='" + C新材质 + "',OutputWeight = '" + C新重量 + "',OutputMeter = '" + C新米数 + "',";
                    sql += "OutputQualityGrade = '"+ C质量等级 + "',OutputQualityInformation = '"+ C质量信息 + "',OutputEndStatus ='"+ C后续状态 + "',";
                    sql += "OutputNext = '"+ C去向 + "',InventoryName ='"+ C品名 + "',QualityStandard = '"+ C执行标准 + "',[OutputColor] = '"+ C颜色 + "',";
                    sql += "[memo] = '"+ C备注 + "' where OutputVolumeNew = '"+ C新卷号 + "'";
                    if (pub.ExecuteSql(pub.ConnectionString, sql, "修改产出的彩涂卷") > 0)
                    {
                        MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK);
                    }
                    else
                    {
                        MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK);
                    }
                }

            }
        }
    }
}
